<?php
/**
 * Created by Moonpie Studio
 * User: Johnzhang
 * Date: 2017/10/28
 * Time: 10:51
 */

namespace app\common\service\view\driver;


use app\common\service\App;
use think\Config;
use think\Url;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Twig\TwigFunction;

class ThinkExtension extends AbstractExtension implements GlobalsInterface
{
    public function getFunctions()
    {
        $func = new TwigFunction('url', function($url = '', $vars = '', $suffix = true, $domain = false){
            return Url::build($url, $vars, $suffix, $domain);
        });
        return [$func];
    }

    public function getGlobals()
    {
        return [
            'app' => [
                'request'=>request(),
                'user' => app('current_account'),
                'debug' => App::$debug,
                'env' => Config::get('app_trace'),
            ]
        ];
    }
    public function getFilters()
    {
        return [];
    }


}